package com.whm.hrmanagement.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.whm.hrmanagement.domain.dto.OaStaffSalaryDto;
import com.whm.hrmanagement.domain.vo.OaSalaryVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.whm.common.annotation.Log;
import com.whm.common.core.controller.BaseController;
import com.whm.common.core.domain.AjaxResult;
import com.whm.common.enums.BusinessType;
import com.whm.hrmanagement.domain.OaSalary;
import com.whm.hrmanagement.service.IOaSalaryService;
import com.whm.common.utils.poi.ExcelUtil;
import com.whm.common.core.page.TableDataInfo;

/**
 * 员工工资Controller
 * 
 * @author whm
 * @date 2024-02-07
 */
@RestController
@RequestMapping("/hrmanagement/salary")
public class OaSalaryController extends BaseController
{
    @Autowired
    private IOaSalaryService oaSalaryService;

    /**
     * 查询员工工资列表
     */
    @PreAuthorize("@ss.hasPermi('hrmanagement:salary:list')")
    @GetMapping("/list")
    public TableDataInfo list(OaSalaryVo oaSalaryVo)
    {
//        startPage();
        List<OaStaffSalaryDto>list = oaSalaryService.selectOaSalaryList2(oaSalaryVo);
        return getDataTable(list);
    }

    /**
     * 导出员工工资列表
     */
    @PreAuthorize("@ss.hasPermi('hrmanagement:salary:export')")
    @Log(title = "员工工资", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OaSalaryVo oaSalaryVo)
    {
        List<OaStaffSalaryDto> list = oaSalaryService.selectOaSalaryList2(oaSalaryVo);
        ExcelUtil<OaStaffSalaryDto> util = new ExcelUtil<OaStaffSalaryDto>(OaStaffSalaryDto.class);
        util.exportExcel(response, list, "员工工资数据");
    }

    /**
     * 获取员工工资详细信息
     */
    @PreAuthorize("@ss.hasPermi('hrmanagement:salary:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(oaSalaryService.selectOaSalaryById(id));
    }

    /**
     * 新增员工工资
     */
    @PreAuthorize("@ss.hasPermi('hrmanagement:salary:add')")
    @Log(title = "员工工资", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OaSalary oaSalary)
    {
        return toAjax(oaSalaryService.insertOaSalary(oaSalary));
    }

    /**
     * 修改员工工资
     */
    @PreAuthorize("@ss.hasPermi('hrmanagement:salary:edit')")
    @Log(title = "员工工资", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OaSalary oaSalary)
    {
        return toAjax(oaSalaryService.updateOaSalary(oaSalary));
    }

    /**
     * 删除员工工资
     */
    @PreAuthorize("@ss.hasPermi('hrmanagement:salary:remove')")
    @Log(title = "员工工资", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(oaSalaryService.deleteOaSalaryByIds(ids));
    }
}
